package com.pengpeng.rabbitmq.declare;

import com.pengpeng.rabbitmq.bean.Result;
import com.pengpeng.rabbitmq.exception.RabbitMQExceptionUtils;
import com.pengpeng.rabbitmq.type.ResultEnum;
import com.pengpeng.rabbitmq.utils.ValidateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 彭鹏
 * @date 2021/10/19.
 */
public abstract class AbstractDeclare {


    public final Log logger = LogFactory.getLog(this.getClass());

    /**
     * 自定义的校验
     *
     * @param object
     */
    public abstract void DefinedValidate(Object object);

    /**
     * 通用校验
     * 1. 校验字段是否是非空
     *
     * @param object
     */
    public void validate(Object object) {
        Result result = ValidateUtils.validate(object);
        if (!ResultEnum.success().equals(result.getCode())) {
            RabbitMQExceptionUtils.throwRabbitMQException(result.getMsg());
        }

        this.DefinedValidate(object);
    }
}
